home *** CD-ROM | disk | FTP | other *** search
- Path: qualcomm.com!not-for-mail
- From: drew@qualcomm.com (Drew Eckhardt)
- Newsgroups: comp.lang.c
- Subject: Re: Implementation of 'strncmpi' function needed
- Date: 18 Apr 1996 02:09:26 -0600
- Organization: QUALCOMM, Incorporated; Boulder, CO, USA
- Message-ID: <4l4tbm$4ko@qualcomm.com>
- References: <4l4q21$qtv@nadine.teleport.com>
- NNTP-Posting-Host: littlebear.qualcomm.com
-
- In article <4l4q21$qtv@nadine.teleport.com>,
- GHouck <hksys@teleport.com> wrote:
- >Howdy,
- >
- >I have to use a quasi-C implementation that does not include
- >a 'strncmpi' function, and therefore have created the following
- >function to accomplish the task.
-
- Some environments have such a function, but use the BSD name (strncasecmp).
-
- < About thirty lines of pain deleted, involving dynamic memory allocation,
- multiple traversals of the strings, and other owies >
-
- What's wrong with something simple like this instead?
-
- #include <ctype.h>
- #include <assert.h>
- int
- strncmpi (const char *a, const char *b, int len) {
- for (;len && toupper(*a) == toupper(*b); --len, ++a, ++b);
- return (toupper(*a) - toupper(*b));
- }
-
- A toupper() implementation for non-hosted ANSI environments, accomodating
- compilers that don't distinguish between const char * and char const *
- (SCO and MicroSoft used to do this), compiler-crutches (such as temporaries
- with a register storage class request), and various other micro-optomizations
- are left as exercises for the reader.
- --
- <a href="http://www.poohsticks.org/drew/">Home Page</a>
- Four boxes : soap, ballot, jury, ammo. | Work: drew@Qualcomm.COM
- Use in that order. | Play: drew@PoohSticks.ORG
-